package com.txunda.zhuohired.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.ants.theantsgo.util.L;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.bean.Pickers;
import com.txunda.zhuohired.bean.user.resume.ExpectPayBean;
import com.txunda.zhuohired.view.PickerScrollView;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2017/11/11 11:48
 * 功能描述：期望薪资
 * 联系方式：jiahuanchen@126.com
 */

public class ExpectPayDialog extends Dialog implements View.OnClickListener {
    private ExpectPayListener expectPayListener;
    private PickerScrollView picker_scroll_view_expect;
    private Context context;
    private List<Pickers> list; // 滚动选择器数据
    private List<ExpectPayBean.DataBean> expectPayList;

    private String industry = "";
    private String industry_id = "";

    public ExpectPayDialog(Context context, List<ExpectPayBean.DataBean> expectPayList, ExpectPayListener
            expectPayListener) {
        super(context, R.style.dialog_style);
        this.context = context;
        this.expectPayListener = expectPayListener;
        this.expectPayList = expectPayList;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_expect_pay);
        picker_scroll_view_expect = findViewById(R.id.picker_scroll_view_expect);
        findViewById(R.id.tv_dialog_expect_pay_close).setOnClickListener(this);
        findViewById(R.id.tv_dialog_expect_pay_cancel).setOnClickListener(this);
        findViewById(R.id.tv_dialog_expect_pay_sure).setOnClickListener(this);
        findViewById(R.id.tv_dialog_expect_pay_discuss).setOnClickListener(this);
        list = new ArrayList<>();
        for (int i = 0; i < expectPayList.size(); i++) {
            list.add(new Pickers(expectPayList.get(i).getSalary(), expectPayList.get(i).getId()));
        }
        // 设置数据，默认选择第一条
        picker_scroll_view_expect.setData(list);
        picker_scroll_view_expect.setSelected(0);
        picker_scroll_view_expect.setOnSelectListener(expectPickerListener);
    }

    // 滚动选择器选中事件
    PickerScrollView.onSelectListener expectPickerListener = new PickerScrollView.onSelectListener() {

        @Override
        public void onSelect(Pickers pickers) {
            System.out.println("选择：" + pickers.getShowId() + "--薪资范围："
                    + pickers.getShowConetnt());
            L.e("===================", "选择：" + pickers.getShowId() + "--薪资范围："
                    + pickers.getShowConetnt());
            industry = pickers.getShowConetnt();
            industry_id = pickers.getShowId();
        }
    };

    @Override
    public void onClick(View view) {
        this.dismiss();
        switch (view.getId()) {
            case R.id.tv_dialog_expect_pay_sure://确认
                if (TextUtils.isEmpty(industry) || TextUtils.isEmpty(industry_id)) {
                    industry = expectPayList.get(0).getSalary();
                    industry_id = expectPayList.get(0).getId();
                    expectPayListener.onExpectPay(industry, industry_id);
                } else {
                    expectPayListener.onExpectPay(industry, industry_id);
                }
                break;
            case R.id.tv_dialog_expect_pay_discuss://面议
                expectPayListener.onExpectPay("面议", "0");
                break;
        }
    }

    public interface ExpectPayListener {
        void onExpectPay(String type, String industry_id);
        //        void onSelectStation(String station, String content, String ask, String id);
    }
}
